<?php

/**
*  判断订明细商品是否在拆单范围
*/
class ome_orderactive 
{

    function getOrderActive($order_id){
        $order_item = kernel::single('ome_mdl_order_items');//商品明细
        $filter = array('order_id' => $order_id,'delete'=>'false');
        $itemList = $order_item->getList('order_id,bn,product_id',$filter);//获取里面明细
        return $itemList;
    }
    //获取取出物料对应关系物料是否把开启拆单功能
    /*返回结果集合	
	array(2) {
	  [1667]=>
	  array(2) {
	    ["ER3150S1501"]=>
	    string(4) "true"
	    ["DS3008G3001"]=>
	    string(5) "false"
	  }
	  ["bool"]=>
	  string(5) "false"
	}
    */
    function getmaterial_autosplit($order_id){
        $item_list = $this->getOrderActive($order_id);
		$material_basic = kernel::single('material_mdl_basic_material_ext');//加载扩展属性
		$data = array();
		$bool = "true";//默认拆单
		 
        foreach ($item_list as $key => $value) {
        	# code...
        	$bm_id = $value['product_id'];
        	$filter = array('bm_id'=>$bm_id);
        	$split = $material_basic->dump($filter);
        	$bn = $value['bn'];
        	if($split['autosplit'] == 'false'){
        		$data[$order_id][$bn] = "false";
        		$bool = "false";//存在不拆单的
        	}else{
        		$data[$order_id][$bn] = "true";
        	}
        	$data['bool']=$bool;
        }       

        return $data;
    }

    function getProduct($material_bn){//输入物料编码获取，销售bn
        $smm = app::get('material')->model('sales_material');
        $bmm = app::get('material')->model('basic_material');
        $msbm = app::get('material')->model('sales_basic_material');

        $filter = array('material_bn'=>$material_bn);

        $bm_ids = $bmm->dump($filter,'bm_id');
        
        $filtermsb = array('bm_id'=>$bm_ids['bm_id']);//获取的基础物料

        $smbmList = $msbm ->getList('sm_id',$filtermsb);//获取绑定关系，可查到销售物料
        $sm_ids = array();
        foreach ($smbmList as $key => $value) {
            # code...
            $sm_ids[] = $value['sm_id'];
        }
        //获取销售物料信息

        $sales_materialfilter = array('sm_id|in'=>$sm_ids);

        $sales_materiallist = $smm->getList('sm_id,sales_material_bn',$sales_materialfilter);//返回销售bnhe sm_id

        return $sales_materiallist; 
    }



    function getsplit($material_bn){//输入基础货号判断是否是需要拆单的商品 autosplit

        $bmm = app::get('material')->model('basic_material');
        $filter = array('material_bn'=>$material_bn);
        $bm_ids = $bmm->dump($filter,'bm_id');
        $material_basic = kernel::single('material_mdl_basic_material_ext');//加载扩展属性
        $split = $material_basic->dump($filter,'autosplit');
        return $split['autosplit'];
    }

    function dodeliveryInfow($deliveryInfo){

        $delivery_items = $deliveryInfo['delivery_items'];
    }
}